package de.koller.so.render.proto;

import de.koller.oceanFramework.gl.util.ImagePreview;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;

public class EclipseLight {

	public BufferedImage eclipsePic( int x ) {
		BufferedImage bi = new BufferedImage( 600, 600, BufferedImage.TYPE_INT_ARGB );
		Graphics2D g = bi.createGraphics();
		
		g.setColor( Color.BLACK );
		g.fillRect( -1, -1, 602, 602 );
		
		g.setColor( Color.YELLOW );
		g.fill( new Ellipse2D.Double( 1, 1, 598, 598 ) );
		
		g.setColor( Color.BLACK );
		g.fill( new Ellipse2D.Double( x+1, 1, 598, 598 ) );
		
		return bi;
	}
	
	public static int lightAt( BufferedImage bi ) {
		int number = 0;
		for( int x = 0; x < bi.getWidth(); x++ )
			for( int y = 0; y < bi.getHeight(); y++ )
				if( bi.getRGB( x, y ) == Color.YELLOW.getRGB() )
					number++;
		return number;
	}
	
	public static void main( String[] args ) {
		float max = lightAt( new EclipseLight().eclipsePic( 1000 ) );
		BufferedImage p = new BufferedImage( 1200, 600, BufferedImage.TYPE_INT_ARGB );
		
		for( int x = -600; x < 600; x ++ ) {
			BufferedImage bi = new EclipseLight().eclipsePic( x );
			float ny = lightAt( bi ) / max * 600f;
			
			for( int y = 0; y < 600; y++ ) {
				if( ny > y )
					p.setRGB( x+600, y, 0xff0000ff );
				else
					p.setRGB( x+600, y, 0xffffffff );
			}
			System.out.println( ((x+600f)/1200f) * 100 + "%" );
		}
		
		ImagePreview.showImage( p, 1200, 600 );
	}
}
